package ooday04;

public class Test {
    public static void main(String[] args) {

        Animal animal2=new Dog("a",1,"a");
        Animal animal=new Animal("s",2,"s"){
            @Override
            void eat() {

            }
        };
        /*
        Master master=new Master();
        Dog dog=new Dog("吞吞",4,"白");
        Fish fish =new Fish("小七",5,"黄");
        Chick chick=new Chick("安全",1,"绿");
        master.feed(dog);
        master.feed(fish);
        master.feed(chick);

         */
        //向上造型
        Animal[] animals=new Animal[5];
        animals[0]=new Dog("吞吞",4,"白");
        animals[1]=new Dog("阿芬",2,"黑");
        animals[2]=new Fish("小七",5,"黄");
        animals[3]=new Fish("小金人",3,"粉");
        animals[4]=new Chick("安全",1,"绿");
        //Master master1=new Master();
        // animals[4]=new Animal("安全", 1, "绿");抽象类不能实例化
        for(int i=0;i< animals.length;i++) {
            System.out.println(animals[i].name);//每个狗狗的名字
            animals[i].eat();//每只动物吃饭
            animals[i].drink();//每只动物喝水
            //master1.feed(animals[i]);
            if (animals[i] instanceof Dog) {//判断animals[i]是否Dog类型的,如果是，就可以强转
                Dog dog = (Dog) animals[i];
                dog.lookHemo();
                dog.swim();
            }
            if (animals[i] instanceof Chick) {////判断animals[i]是否Chick类型的,如果是，就可以强转
                Chick chick = (Chick) animals[i];
                if (animals[i] instanceof Fish) {//判断animals[i]是Fish类型的,如果是，就可以强转
                    Fish fish = (Fish) animals[i];
                    fish.swim();
                }
                if (animals[i] instanceof Swim) {//判断animals[i]的类型是否能实现Swim接口
                    Swim swim = (Swim) animals[i];
                    swim.swim();
                }
            }

//        Animal a=new Dog("奥斯卡",22,"黑");
//        Dog[] dogs=new Dog[3];
//        dogs[0]=new Dog("吞吞",4,"白");
//        dogs[1]=new Dog("奥小七",6,"黄");
//        dogs[2]=new Dog("奥斯卡",8,"黑白");
//        for(int i=0;i< dogs.length;i++){
//            System.out.println(dogs[i].name);
//            dogs[i].eat();
//            dogs[i].drink();
//            dogs[i].lookHemo();
//            dogs[i].swim();
//        }
//        Chick[] chicks=new Chick[2];
//        chicks[0]=new Chick("小金人",1,"黄");
//        chicks[1]=new Chick("小黑",2,"黑");
//        for(int i=0;i< chicks.length;i++){
//            System.out.println(chicks[i].name);
//            chicks[i].eat();
//            chicks[i].drink();
//            chicks[i].layEggs();
//        }
//        Fish[] fish=new Fish[4];
//        fish[0]=new Fish("阿芬",25,"黑");
//        fish[1]=new Fish("阿星",15,"蓝");
//        fish[2]=new Fish("阿飘",18,"黄");
//        fish[3]=new Fish("阿莹",20,"白");
//        for(int i=0;i< fish.length;i++){
//            System.out.println(fish[i].name);
//            fish[i].eat();
//            fish[i].swim();
//            fish[i].drink();
//        }
        }
    }
}
